//
// Created by longyunbo on 6/23/21.
//

#include "BootClassLoad.h"


InstanceKlass* BootClassLoad::getInstanceKlass() {
    return _mainKlass;
}

void BootClassLoad::setInstanceKlass(InstanceKlass* instanceKlass){
    _mainKlass = instanceKlass;
}

InstanceKlass* BootClassLoad::loadKlass(string className,bool b){
       printf("double \n");
       //查看缓存中有没有
       _itclassLoaderData = classLoaderData.find(className);
       if( _itclassLoaderData != classLoaderData.end() ){
            return _itclassLoaderData->second;
       }else{
            //没有 去加载
            InstanceKlass* in = readAndParse(className);
            if(b){
                resolveKlass();
            }
           return in;
       }
}

InstanceKlass* BootClassLoad::loadKlass(string name){
    printf(" loadKlass \n");
    return loadKlass(name,true);
}

//真正的解析开始
InstanceKlass* BootClassLoad::readAndParse(string className){

    printf("readAndParse \n");

    string replaceName = _dataTranslate->replaceAWithX(className);

    string filePath = searchFile + replaceName + SUFFIX ;
    char* classLoadPath = (char*)filePath.c_str() ;

    FILE* fw=fopen(classLoadPath,"r");

    if( fw == NULL ){
        printf(" Exception Class Not Found  BootClassLoad.ccp File 50 row \n");
        exit(-1);
    }

    InstanceKlass* in = classFileParser->parseClassFile(fw);

    return in;
}


void BootClassLoad::resolveKlass(){

}

BootClassLoad ::  ~BootClassLoad(){

    if( _dataTranslate == NULL ){
        printf(" BootClassLoad  释放 _dataTranslate ");
        delete _dataTranslate;
    }

}


















